package thread;

public class CurrentThreadDemo {
    public static void main(String[] args) {
        Thread main = Thread.currentThread();
        System.out.println("主线程:" + main);
        showThreadInfo();

    }

    public static void showThreadInfo() {
        //调用showThreadInfo方法的线程
        Thread t = Thread.currentThread();
        System.out.println("调用showThreadInfo方法的线程是:" + t);

        /*
            线程提供了一组用于获取该线程相关信息的方法
         */
        //获取线程的名字
        String name = t.getName();
        System.out.println("name:" + name);

        //id:唯一表示
        long id = t.getId();
        System.out.println("唯一标识:" + id);

        //线程的优先级(1-10) 1最低，10最高，5为默认值
        int priority = t.getPriority();
        System.out.println("优先级:" + priority);

        //线程是否活着
        boolean isAlive = t.isAlive();
        //是否为守护线程
        boolean isDaemon = t.isDaemon();
        //是否被中断
        boolean isInterrupted = t.isInterrupted();

        System.out.println("isAlive:" + isAlive);
        System.out.println("isDaemon:" + isDaemon);
        System.out.println("isInterrupted:" + isInterrupted);


    }
}
